<?php


namespace app\common\service;


use app\common\exception\ParameterFailedException;
use think\facade\Config;

class SF
{
    public static function getRouteInfo($data)
    {
        try {
            $requestID = create_uuid();
            $timestamp = time();
            $partnerID = Config::get('main.sf.fq_id');
            $checkword = Config::get('main.sf.fq_secret');
            //通过MD5和BASE64生成数字签名
            $msgDigest   = base64_encode(md5((urlencode(json_encode($data) . $timestamp . $checkword)), TRUE));
            $serviceCode = 'EXP_RECE_SEARCH_ROUTES';
            $post_data   = [
                'partnerID'   => $partnerID,
                'requestID'   => $requestID,
                'serviceCode' => $serviceCode,
                'timestamp'   => $timestamp,
                'msgDigest'   => $msgDigest,
                'msgData'     => json_encode($data),
            ];

            //        $packageInfo             = curl_post('https://sfapi-sbox.sf-express.com/std/service', $post_data, $code);
            $packageInfo   = send_post('https://sfapi-sbox.sf-express.com/std/service', $post_data);
            $res           = json_decode($packageInfo, true);
            $apiResultData = json_decode($res['apiResultData'], true);
            if ($apiResultData['errorCode'] === 'S0000') {
                return $apiResultData['msgData'];
            }
            throw new ParameterFailedException(['msg' => '信息获取失败']);
        } catch (\Exception $e) {
            throw $e;
        }
    }
}